<?php
$d3_abs_file = XOOPS_TRUST_PATH . '/modules/d3forum/class/D3commentAbstract.class.php';
if (!file_exists($d3_abs_file)) return;
if (isset($mydirname)) {
	$module_handler =& xoops_gethandler('module') ;
	$xoopsModule =& $module_handler->getByDirname($mydirname) ;
	$config_handler =& xoops_gethandler('config') ;
	$module_config =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
	if (empty($module_config['comment_dirname']) || empty($module_config['comment_forum_id'])) {
		return;
	}
} else {
	return;
}
require_once $d3_abs_file;

// a class for d3forum comment integration
class linksCommentContent extends D3commentAbstract
{

/*	function linksCommentContent($d3forum_dirname, $target_dirname, $target_trustdirname = '')
	{
		parent::D3commentAbstract($d3forum_dirname, $target_dirname, $target_trustdirname);
	}*/

	function displayCommentsCount($params)
	{
		$comments_count = $this->countComments($this->restructParams($params));

		echo intval($comments_count);
	}

	function fetchSummary($external_link_id)
	{
		require_once realpath(dirname(__FILE__)) . '/links_Base.class.php';

		$content_id = intval($external_link_id);
		$mydirname = $this->mydirname;
		if (preg_match('/[^0-9a-zA-Z_-]/', $mydirname)) die('Invalid mydirname');

		// $Links OBJ
		$links_comment = links_Base::getInstance($mydirname);

		if ($link = $links_comment->getDataByLid($content_id)) {

			// ADD Screen Shots
			$screenshot = '' ;
			if ($link['adult']) {
				$screenshot = '<div style="float:left;padding-right:6px;">';
				$screenshot.= '<img src="'. $links_comment->myurl .'/images/warning128.gif" /></div>' ;
			} else {
				if ($link['capture']) {
					$screenshot = '<div style="float:left;padding-right:6px;">';
					$screenshot.= '<img src="'. $links_comment->cache_url .'/'. $link['lid'] .'.jpg" /></div>' ;
				} else if ($links_comment->screen_shot_service && !empty($link['url'])){
					$shoturl    = $links_comment->screen_shot_service . $link['url'] ;
					$screenshot = '<div style="float:left;padding-right:6px;">';
					$screenshot.= '<img src="'. $shoturl .'" height="128" width="128" /></div>' ;
				}
			}

			return array(
				'dirname'     => $mydirname,
				'module_name' => $links_comment->module_name,
				'subject'     => $link['title'],
				'uri'         => $link['link_url'],
				'summary'     => $screenshot . $link['description'],
			) ;

		} else {
			return;
		}

	}
}
